package com.fourth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fourth.dao.UbCommentDao;
import com.fourth.dao.UbOrderDao;
import com.fourth.service.UbOrderService;
import com.fourth.util.GetUidUtil;
import com.ljx.entity.Order;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Mr.ma
 * @since 2023/3/3 15:21
 **/
@Service
public class UbOrderServiceImpl implements UbOrderService {
    @Resource
    private UbOrderDao ubOrderDao;

    @Resource
    private UbCommentDao ubCommentDao;

    @Override
    public int insert(Order order) {
        return ubOrderDao.insert(order);
    }

    @Override
    public String getGoodsName(String goodsid) {
        return ubOrderDao.getGoodsName(goodsid);
    }

    @Override
    public List<Order> hasBuyThisGoods(String id) {
        String uid = GetUidUtil.getUid();
        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        wrapper.eq("goodsid",id);
        wrapper.eq("uid",uid);
        wrapper.eq("state",0);
        List<Order> orders = ubOrderDao.selectList(wrapper);
        return orders;
    }

    @Override
    public List<Order> getOrderByCode (String code) {
        List<Order> orders = ubOrderDao.selectWithGoods(code);
        return orders;
    }

    @Override
    public List<Order> noCommentOrder(String id) {
        String uid = GetUidUtil.getUid();
        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        wrapper.eq("goodsid",id);
        wrapper.eq("uid",uid);
        wrapper.eq("state",0);
        wrapper.eq("commentstatus",0);
        List<Order> orders = ubOrderDao.selectList(wrapper);
        return orders;
    }

    @Override
    public int updateById(Order order) {
        return ubOrderDao.updateById(order);
    }

    @Override
    public int changeState(String code, Integer state) {
        return ubOrderDao.changeState(code,state);
    }
}
